package xgenerator.ui.swing;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;

public class CheckBoxCellEditor extends DefaultCellEditor implements ItemListener {

	private JCheckBox checkBox;

	public CheckBoxCellEditor(JCheckBox checkBox) {
		super(checkBox);
	}

	/**
	 * <p>
	 * Title：
	 * </p>
	 * <p>
	 * 
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
	 * @param e
	 */
	public void itemStateChanged(ItemEvent e) {
		super.fireEditingStopped();
	}

	/**
	 * <p>
	 * Title：
	 * </p>
	 * <p>
	 * 
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @see javax.swing.DefaultCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
	 * @param table
	 * @param value
	 * @param isSelected
	 * @param row
	 * @param column
	 * @return
	 */
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		if (value == null) {
			return null;
		}
		this.checkBox = (JCheckBox) value;
		this.checkBox.addItemListener(this);
		return (Component) value;
	}

	/**
	 * <p>
	 * Title：
	 * </p>
	 * <p>
	 * Description：
	 * </p>
	 * 
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @see javax.swing.DefaultCellEditor#getCellEditorValue()
	 * @return
	 */
	public Object getCellEditorValue() {
		this.checkBox.removeItemListener(this);
		return checkBox;
	}

}
